package com.zhiwang.planet.mvp.p

import com.zhiwang.planet.BuildConfig
import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvp.v.AlipayView
import com.zhiwang.planet.mvp.v.DiamondPayView
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.util.androidSchedule
import com.zhiwang.planet.util.responseFunc
import com.zhiwang.planet.util.responseVoidFunc
import com.uber.autodispose.AutoDispose.autoDisposable
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.util.AppHelper
import javax.inject.Inject

@ActivityScope
class PayPresenter @Inject constructor(var restApi: RestApi, var converter: AndroidLifecycleScopeProvider) {

    lateinit var aliPayView: AlipayView
    lateinit var diamondPayView: DiamondPayView

    fun getAlipaySign(userid: String, viptype: String, payType: String) {
        restApi.getAlipaySign(baseUrl() + "payment/pay", userid, viptype, payType, "0")
                .androidSchedule()
                .responseFunc()
                .`as`(autoDisposable(converter))
                .subscribe({
                    aliPayView.onAlipay(it)
                }, {
                    aliPayView.onError(it)
                }, {

                })
    }

    fun payVipByDiamond(userid: String, viptype: String, payType: String) {
        restApi.payByDiamond(baseUrl() + "ucenter_payment/do_quzuan", userid, viptype, payType, "0")
                .androidSchedule()
                .responseVoidFunc()
                .`as`(autoDisposable(converter))
                .subscribe({
                }, {
                    diamondPayView.onError(it)
                }, {
                    diamondPayView.onDiamondPay()
                })
    }

    fun baseUrl(): String {
        return if (AppHelper.testEnv()) BuildConfig.DEBUG_Ji7_BASE_URL else BuildConfig.Ji7_BASE_URL
    }
}